$(function() {

$.context = {};

$.context.create = function($target)
{
	var target = $target[0];

	target.context =
	{
		id : $.utils.generateAddress(),

		process : function()
		{
			target.context.interval *= 2;

			clearTimeout(target.context.timeoutObject);

			if($(target).is(":visible"))
				$.ajax({
					url: "context",
					data: target.context.id,
					success: target.context.callback,
					dataType: "json"
				});

			target.context.timeoutObject = setTimeout(target.context.process, target.context.interval);
		},

		callback : function(data)
		{
			target.context.interval = 100;

			$.input.searchCallback(data, target);
		},

		stop : function()
		{
			clearTimeout(target.context.timeoutObject);
		},

		start : function(term)
		{
			target.context.stop();

			target.context.interval = 100;

			$.input.search(term, target);

			target.context.process();
		},

		interval : 100
	};

	target.context.timeoutObject = setTimeout(target.context.process, target.context.interval);

	target.context.process();

	target.setAttribute("contextid", target.context.id);
}
})
